//c3p0，如何加入配置文件

package Utils;

import java.sql.Connection;

import java.sql.SQLException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;  //c3p0

public class DataSourceUtils {
	private static ComboPooledDataSource ds=new ComboPooledDataSource();  //连接池
	
	/**
	 * 获取数据源
	 * @return 连接池
	 */
	public static DataSource getDataSource(){
		return ds;
	}
	
	/**
	 * 获取数据源
	 * @return  连接
	 * @throws SQLException
	 */
	public static Connection getConnection() throws SQLException{
		return ds.getConnection();
	}
	
	public static void closeResource(Connection conn,PreparedStatement st,ResultSet rs){
		closeResultSet(rs);
		closePreparedStatement(st);
		closeConnection(conn);
	}
	public static void closeConnection(Connection conn){
		if(conn!=null){
			try{
				conn.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		conn=null;
	}
	public static void closePreparedStatement(PreparedStatement st){
		if(st!=null){
			try{
				st.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		st=null;
	}
	public static void closeResultSet(ResultSet rs){
		if(rs!=null){
			try{
				rs.close();
			}catch(Exception e){
				e.printStackTrace();
			}
		}
		rs=null;
	}
}
